package 每日一题;

public class 直线上最多的点 {

    public int maxPoints(int[][] points) {
        int n = points.length;
        int ans = 1;
        for (int i = 0; i < n; i++) {
            int[] x = points[i];
            for (int j = i+1; j <n; j++) {
                int[] y = points[j];
                int cnt = 2;
                for (int k = j+1; k < n; k++) {
                    int[] p = points[k];
                    //公式：y-y1/x-x1 = y-y2/x-x2 则斜率相等
                    int m1 = ((y[1]-x[1])*(p[0]-y[0]));
                    int m2 = ((p[1]-y[1])*(y[0]-x[0]));
                    if (m1==m2)
                        cnt++;
                }
                ans = Math.max(ans,cnt);
            }
        }
        return ans;
    }
}
